/*
 * libroxsd - a portable, lightweight XSD validation library
 * Copyright (C) 2012  Emmanuel Deloget
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301  USA
 */

#include <roxml.h>
#include "roxsd-list.h"
#include "roxsd-compiler.h"
#include "roxsd-compiler-xsdtype.h"
#include "roxsd-compiler-schema.h"

static xsdtype_t *roxsdi_make_xsd_include(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *t;

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	sym = roxsdi_xsdtype_new(NULL, "t_include", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_import(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *t;

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	sym = roxsdi_xsdtype_new(NULL, "t_import", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_redefine(void)
{
	xsdtype_t *sym;
	xsdtype_t *st;

	st = roxsdi_choice_new(0, UNBOUNDED);
	(void)roxsdi_xsdtype_add_element(st, "annotation", "t_annotation");
	(void)roxsdi_xsdtype_add_element(st, "simpleType", "t_simple_type");
	(void)roxsdi_xsdtype_add_element(st, "compleType", "t_complex_type");
	(void)roxsdi_xsdtype_add_element(st, "group", "t_group");
	(void)roxsdi_xsdtype_add_element(st, "attributeGroup", "t_attribute_group");

	sym = roxsdi_xsdtype_new(NULL, "t_redefine", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, st);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_annotation(void)
{
	xsdtype_t *sym;
	xsdtype_t *st;

	st = roxsdi_choice_new(0, UNBOUNDED);
	(void)roxsdi_xsdtype_add_element(st, "appinfo", "t_appinfo");
	(void)roxsdi_xsdtype_add_element(st, "documentation", "t_documentation");

	sym = roxsdi_xsdtype_new(NULL, "t_annotation", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, st);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_simple_type(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *st;
	xsdtype_t *t;

	st = roxsdi_choice_new(0, UNBOUNDED);
	(void)roxsdi_xsdtype_add_element(st, "restriction", "t_restriction_stype");
	(void)roxsdi_xsdtype_add_element(st, "list", "t_list");
	(void)roxsdi_xsdtype_add_element(st, "union", "t_union");

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;
	(void)roxsdi_xsdtype_add_child(seq, st);

	sym = roxsdi_xsdtype_new(NULL, "t_simple_type", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_complex_type(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *seq2;
	xsdtype_t *st1;
	xsdtype_t *st2;
	xsdtype_t *st3;
	xsdtype_t *t;

	st1 = roxsdi_choice_new(0, 1);
	(void)roxsdi_xsdtype_add_element(st1, "group", "t_group");
	(void)roxsdi_xsdtype_add_element(st1, "all", "t_all");
	(void)roxsdi_xsdtype_add_element(st1, "choice", "t_choice");
	(void)roxsdi_xsdtype_add_element(st1, "sequence", "t_sequence");

	st2 = roxsdi_choice_new(0, UNBOUNDED);
	(void)roxsdi_xsdtype_add_element(st1, "attribute", "t_attribute");
	(void)roxsdi_xsdtype_add_element(st1, "attributeGroup", "t_attribute_group");

	seq2 = roxsdi_sequence_new();
	(void)roxsdi_xsdtype_add_child(seq2, st1);
	(void)roxsdi_xsdtype_add_child(seq2, st2);
	t = roxsdi_xsdtype_add_element(seq2, "anyAttribute", "t_any_attribute");
	t->minocc = 0;
	t->maxocc = 1;

	st3 = roxsdi_choice_new(0, 1);
	(void)roxsdi_xsdtype_add_element(st3, "simpleContent", "t_simple_content");
	(void)roxsdi_xsdtype_add_element(st3, "complexContent", "t_complex_content");
	(void)roxsdi_xsdtype_add_child(st3, seq2);

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	(void)roxsdi_xsdtype_add_child(seq, st3);

	sym = roxsdi_xsdtype_new(NULL, "t_complex_type", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_group(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *st;
	xsdtype_t *t;

	st = roxsdi_choice_new(0, 1);
	(void)roxsdi_xsdtype_add_element(st, "all", "t_all");
	(void)roxsdi_xsdtype_add_element(st, "choice", "t_choice");
	(void)roxsdi_xsdtype_add_element(st, "sequence", "t_sequence");

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	(void)roxsdi_xsdtype_add_child(seq, st);

	sym = roxsdi_xsdtype_new(NULL, "t_group", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_attribute_group(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *st;
	xsdtype_t *t;

	st = roxsdi_choice_new(0, UNBOUNDED);
	(void)roxsdi_xsdtype_add_element(st, "attribute", "t_attribute");
	(void)roxsdi_xsdtype_add_element(st, "attributeGroup", "t_attribute_group");

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	(void)roxsdi_xsdtype_add_child(seq, st);

	t = roxsdi_xsdtype_add_element(seq, "anyAttribute", "t_any_attribute");
	t->minocc = 0;
	t->maxocc = 1;

	sym = roxsdi_xsdtype_new(NULL, "t_attribute_group", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_element(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *ch1;
	xsdtype_t *ch2;
	xsdtype_t *t;

	ch1 = roxsdi_choice_new(0, 1);
	(void)roxsdi_xsdtype_add_element(ch1, "simpleType", "t_simple_type");
	(void)roxsdi_xsdtype_add_element(ch1, "complexType", "t_complex_type");

	ch2 = roxsdi_choice_new(0, UNBOUNDED);
	(void)roxsdi_xsdtype_add_element(ch2, "unique", "t_unique");
	(void)roxsdi_xsdtype_add_element(ch2, "key", "t_key");
	(void)roxsdi_xsdtype_add_element(ch2, "keyref", "t_keyref");

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	(void)roxsdi_xsdtype_add_child(seq, ch1);
	(void)roxsdi_xsdtype_add_child(seq, ch2);

	sym = roxsdi_xsdtype_new(NULL, "t_element", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_attribute(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *t;

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;
	t = roxsdi_xsdtype_add_element(seq, "simpleType", "t_simple_type");
	t->minocc = 0;
	t->maxocc = 1;

	sym = roxsdi_xsdtype_new(NULL, "t_attribute", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_notation(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *t;

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	sym = roxsdi_xsdtype_new(NULL, "t_notation", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_all(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *t;

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;
	t = roxsdi_xsdtype_add_element(seq, "element", "t_element");
	t->minocc = 0;
	t->maxocc = UNBOUNDED;

	sym = roxsdi_xsdtype_new(NULL, "t_all", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_any_attribute(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *t;

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	sym = roxsdi_xsdtype_new(NULL, "t_any_attribute", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_appinfo(void)
{
	xsdtype_t *sym;

	sym = roxsdi_xsdtype_new(NULL, "t_appinfo", 1, 1, ROXSDI_TYPE_SIMPLETYPE);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_documentation(void)
{
	xsdtype_t *sym;

	sym = roxsdi_xsdtype_new(NULL, "t_documentation", 1, 1, ROXSDI_TYPE_SIMPLETYPE);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_choice(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *ch;
	xsdtype_t *t;

	ch = roxsdi_choice_new(0, UNBOUNDED);
	(void)roxsdi_xsdtype_add_element(ch, "element", "t_element");
	(void)roxsdi_xsdtype_add_element(ch, "group", "t_group");
	(void)roxsdi_xsdtype_add_element(ch, "choice", "t_choice");
	(void)roxsdi_xsdtype_add_element(ch, "sequence", "t_sequence");
	(void)roxsdi_xsdtype_add_element(ch, "any", "t_any");

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	(void)roxsdi_xsdtype_add_child(seq, ch);

	sym = roxsdi_xsdtype_new(NULL, "t_choice", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_any(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *t;

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	sym = roxsdi_xsdtype_new(NULL, "t_any", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_complex_content(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *ch;
	xsdtype_t *t;

	ch = roxsdi_choice_new(0, UNBOUNDED);
	(void)roxsdi_xsdtype_add_element(ch, "restriction", "t_restriction_ccontent");
	(void)roxsdi_xsdtype_add_element(ch, "extension", "t_extension");

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	(void)roxsdi_xsdtype_add_child(seq, ch);

	sym = roxsdi_xsdtype_new(NULL, "t_complex_content", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_extension(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *ch1;
	xsdtype_t *ch2;
	xsdtype_t *t;

	ch1 = roxsdi_choice_new(0, 1);
	(void)roxsdi_xsdtype_add_element(ch1, "group", "t_group");
	(void)roxsdi_xsdtype_add_element(ch1, "all", "t_all");
	(void)roxsdi_xsdtype_add_element(ch1, "choice", "t_choice");
	(void)roxsdi_xsdtype_add_element(ch1, "sequence", "t_sequence");

	ch2 = roxsdi_choice_new(0, UNBOUNDED);
	(void)roxsdi_xsdtype_add_element(ch2, "attribute", "t_attribute");
	(void)roxsdi_xsdtype_add_element(ch2, "attributeGroup", "t_attribute_group");

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	(void)roxsdi_xsdtype_add_child(seq, ch1);
	(void)roxsdi_xsdtype_add_child(seq, ch2);

	t = roxsdi_xsdtype_add_element(seq, "anyAttribute", "t_any_attribute");
	t->minocc = 0;
	t->maxocc = 1;

	sym = roxsdi_xsdtype_new(NULL, "t_extension", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_key(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *t;

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	(void)roxsdi_xsdtype_add_element(seq, "selector", "t_selector");

	t = roxsdi_xsdtype_add_element(seq, "field", "t_field");
	t->minocc = 1;
	t->maxocc = UNBOUNDED;

	sym = roxsdi_xsdtype_new(NULL, "t_key", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_keyref(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *t;

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	(void)roxsdi_xsdtype_add_element(seq, "selector", "t_selector");

	t = roxsdi_xsdtype_add_element(seq, "field", "t_field");
	t->minocc = 1;
	t->maxocc = UNBOUNDED;

	sym = roxsdi_xsdtype_new(NULL, "t_keyref", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_field(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *t;

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	sym = roxsdi_xsdtype_new(NULL, "t_field", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_list(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *t;

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	t = roxsdi_xsdtype_add_element(seq, "simpleType", "t_simple_type");
	t->minocc = 0;
	t->maxocc = 1;

	sym = roxsdi_xsdtype_new(NULL, "t_list", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_selector(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *t;

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	sym = roxsdi_xsdtype_new(NULL, "t_selector", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_sequence(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *ch1;
	xsdtype_t *t;

	ch1 = roxsdi_choice_new(0, UNBOUNDED);
	(void)roxsdi_xsdtype_add_element(ch1, "element", "t_element");
	(void)roxsdi_xsdtype_add_element(ch1, "group", "t_group");
	(void)roxsdi_xsdtype_add_element(ch1, "choice", "t_choice");
	(void)roxsdi_xsdtype_add_element(ch1, "sequence", "t_sequence");
	(void)roxsdi_xsdtype_add_element(ch1, "any", "t_any");

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	(void)roxsdi_xsdtype_add_child(seq, ch1);

	sym = roxsdi_xsdtype_new(NULL, "t_sequence", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_simple_content(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *ch;
	xsdtype_t *t;

	ch = roxsdi_choice_new(0, UNBOUNDED);
	(void)roxsdi_xsdtype_add_element(ch, "restriction", "t_restriction_scontent");
	(void)roxsdi_xsdtype_add_element(ch, "extension", "t_extension");

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	(void)roxsdi_xsdtype_add_child(seq, ch);

	sym = roxsdi_xsdtype_new(NULL, "t_simple_content", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_union(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *t;

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	t = roxsdi_xsdtype_add_element(seq, "simpleType", "t_simple_type");
	t->minocc = 0;
	t->maxocc = UNBOUNDED;

	sym = roxsdi_xsdtype_new(NULL, "t_union", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_unique(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *t;

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	(void)roxsdi_xsdtype_add_element(seq, "selector", "t_selector");

	t = roxsdi_xsdtype_add_element(seq, "field", "t_field");
	t->minocc = 1;
	t->maxocc = UNBOUNDED;

	sym = roxsdi_xsdtype_new(NULL, "t_unique", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_restriction_stype(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *ch;
	xsdtype_t *t;

	ch = roxsdi_choice_new(0, UNBOUNDED);
	(void)roxsdi_xsdtype_add_element(ch, "minExclusive", "t_min_exclusive");
	(void)roxsdi_xsdtype_add_element(ch, "minInclusive", "t_min_inclusive");
	(void)roxsdi_xsdtype_add_element(ch, "maxExclusive", "t_max_exclusive");
	(void)roxsdi_xsdtype_add_element(ch, "maxInclusive", "t_max_inclusive");
	(void)roxsdi_xsdtype_add_element(ch, "totalDigits", "t_total_digits");
	(void)roxsdi_xsdtype_add_element(ch, "fractionDigits", "t_fraction_digits");
	(void)roxsdi_xsdtype_add_element(ch, "length", "t_length");
	(void)roxsdi_xsdtype_add_element(ch, "minLength", "t_min_length");
	(void)roxsdi_xsdtype_add_element(ch, "maxLength", "t_max_length");
	(void)roxsdi_xsdtype_add_element(ch, "enumeration", "t_enumeration");
	(void)roxsdi_xsdtype_add_element(ch, "whiteSpace", "t_white_space");
	(void)roxsdi_xsdtype_add_element(ch, "pattern", "t_pattern");

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	t = roxsdi_xsdtype_add_element(seq, "simpleType", "t_simple_type");
	t->minocc = 0;
	t->maxocc = 1;

	(void)roxsdi_xsdtype_add_child(seq, ch);

	sym = roxsdi_xsdtype_new(NULL, "t_restriction_stype", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_enumeration(void)
{
	xsdtype_t *sym;

	sym = roxsdi_xsdtype_new(NULL, "t_enumeration", 1, 1, ROXSDI_TYPE_SIMPLETYPE);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_pattern(void)
{
	xsdtype_t *sym;

	sym = roxsdi_xsdtype_new(NULL, "t_pattern", 1, 1, ROXSDI_TYPE_SIMPLETYPE);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_min_inclusive(void)
{
	xsdtype_t *sym;

	sym = roxsdi_xsdtype_new(NULL, "t_min_inclusive", 1, 1, ROXSDI_TYPE_SIMPLETYPE);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_max_inclusive(void)
{
	xsdtype_t *sym;

	sym = roxsdi_xsdtype_new(NULL, "t_max_inclusive", 1, 1, ROXSDI_TYPE_SIMPLETYPE);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_min_exclusive(void)
{
	xsdtype_t *sym;

	sym = roxsdi_xsdtype_new(NULL, "t_min_exclusive", 1, 1, ROXSDI_TYPE_SIMPLETYPE);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_max_exclusive(void)
{
	xsdtype_t *sym;

	sym = roxsdi_xsdtype_new(NULL, "t_max_exclusive", 1, 1, ROXSDI_TYPE_SIMPLETYPE);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_min_length(void)
{
	xsdtype_t *sym;

	sym = roxsdi_xsdtype_new(NULL, "t_min_length", 1, 1, ROXSDI_TYPE_SIMPLETYPE);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_max_length(void)
{
	xsdtype_t *sym;

	sym = roxsdi_xsdtype_new(NULL, "t_max_length", 1, 1, ROXSDI_TYPE_SIMPLETYPE);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_length(void)
{
	xsdtype_t *sym;

	sym = roxsdi_xsdtype_new(NULL, "t_length", 1, 1, ROXSDI_TYPE_SIMPLETYPE);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_white_space(void)
{
	xsdtype_t *sym;

	sym = roxsdi_xsdtype_new(NULL, "t_white_space", 1, 1, ROXSDI_TYPE_SIMPLETYPE);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_total_digits(void)
{
	xsdtype_t *sym;

	sym = roxsdi_xsdtype_new(NULL, "t_total_digits", 1, 1, ROXSDI_TYPE_SIMPLETYPE);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_fraction_digits(void)
{
	xsdtype_t *sym;

	sym = roxsdi_xsdtype_new(NULL, "t_fraction_digits", 1, 1, ROXSDI_TYPE_SIMPLETYPE);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_restriction_scontent(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *ch;
	xsdtype_t *ch2;
	xsdtype_t *t;

	ch = roxsdi_choice_new(0, UNBOUNDED);
	(void)roxsdi_xsdtype_add_element(ch, "minExclusive", "t_min_exclusive");
	(void)roxsdi_xsdtype_add_element(ch, "minInclusive", "t_min_inclusive");
	(void)roxsdi_xsdtype_add_element(ch, "maxExclusive", "t_max_exclusive");
	(void)roxsdi_xsdtype_add_element(ch, "maxInclusive", "t_max_inclusive");
	(void)roxsdi_xsdtype_add_element(ch, "totalDigits", "t_total_digits");
	(void)roxsdi_xsdtype_add_element(ch, "fractionDigits", "t_fraction_digits");
	(void)roxsdi_xsdtype_add_element(ch, "length", "t_length");
	(void)roxsdi_xsdtype_add_element(ch, "minLength", "t_min_length");
	(void)roxsdi_xsdtype_add_element(ch, "maxLength", "t_max_length");
	(void)roxsdi_xsdtype_add_element(ch, "enumeration", "t_enumeration");
	(void)roxsdi_xsdtype_add_element(ch, "whiteSpace", "t_white_space");
	(void)roxsdi_xsdtype_add_element(ch, "pattern", "t_pattern");

	ch2 = roxsdi_choice_new(0, UNBOUNDED);
	(void)roxsdi_xsdtype_add_element(ch2, "attribute", "t_attribute");
	(void)roxsdi_xsdtype_add_element(ch2, "attributeGroup", "t_attribute_group");

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	t = roxsdi_xsdtype_add_element(seq, "simpleType", "t_simple_type");
	t->minocc = 0;
	t->maxocc = 1;

	(void)roxsdi_xsdtype_add_child(seq, ch);
	(void)roxsdi_xsdtype_add_child(seq, ch2);

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "anyAttribute", "t_any_attribute");
	t->minocc = 0;
	t->maxocc = 1;

	sym = roxsdi_xsdtype_new(NULL, "t_restriction_scontent", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_restriction_ccontent(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *ch;
	xsdtype_t *ch2;
	xsdtype_t *t;

	ch = roxsdi_choice_new(0, UNBOUNDED);
	(void)roxsdi_xsdtype_add_element(ch, "group", "t_group");
	(void)roxsdi_xsdtype_add_element(ch, "all", "t_all");
	(void)roxsdi_xsdtype_add_element(ch, "choice", "t_choice");
	(void)roxsdi_xsdtype_add_element(ch, "sequence", "t_sequence");

	ch2 = roxsdi_choice_new(0, UNBOUNDED);
	(void)roxsdi_xsdtype_add_element(ch2, "attribute", "t_attribute");
	(void)roxsdi_xsdtype_add_element(ch2, "attributeGroup", "t_attribute_group");

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "annotation", "t_annotation");
	t->minocc = 0;
	t->maxocc = 1;

	(void)roxsdi_xsdtype_add_child(seq, ch);
	(void)roxsdi_xsdtype_add_child(seq, ch2);

	seq = roxsdi_sequence_new();
	t = roxsdi_xsdtype_add_element(seq, "anyAttribute", "t_any_attribute");
	t->minocc = 0;
	t->maxocc = 1;

	sym = roxsdi_xsdtype_new(NULL, "t_restriction_ccontent", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static xsdtype_t *roxsdi_make_xsd_schema(void)
{
	xsdtype_t *sym;
	xsdtype_t *seq;
	xsdtype_t *ch1;
	xsdtype_t *ch2;
	xsdtype_t *t;

	ch1 = roxsdi_choice_new(0, UNBOUNDED);
	(void)roxsdi_xsdtype_add_element(ch1, "include", "t_include");
	(void)roxsdi_xsdtype_add_element(ch1, "import", "t_import");
	(void)roxsdi_xsdtype_add_element(ch1, "redefine", "t_redefine");
	(void)roxsdi_xsdtype_add_element(ch1, "annotation", "t_annotation");

	ch2 = roxsdi_choice_new(0, UNBOUNDED);
	(void)roxsdi_xsdtype_add_element(ch2, "simpleType", "t_simple_type");
	(void)roxsdi_xsdtype_add_element(ch2, "complexType", "t_complex_type");
	(void)roxsdi_xsdtype_add_element(ch2, "group", "t_group");
	(void)roxsdi_xsdtype_add_element(ch2, "attributeGroup", "t_attribute_group");
	(void)roxsdi_xsdtype_add_element(ch2, "element", "t_element");
	(void)roxsdi_xsdtype_add_element(ch2, "attribute", "t_attribute");
	(void)roxsdi_xsdtype_add_element(ch2, "notation", "t_notation");
	(void)roxsdi_xsdtype_add_element(ch2, "annotation", "t_annotation");

	seq = roxsdi_sequence_new();
	(void)roxsdi_xsdtype_add_child(seq, ch1);
	(void)roxsdi_xsdtype_add_child(seq, ch2);

	sym = roxsdi_xsdtype_new(NULL, "t_schema", 1, 1, ROXSDI_TYPE_COMPLEXTYPE);
	(void)roxsdi_xsdtype_add_child(sym, seq);

	return sym;
}

static int roxsdi_compiler_register_schema_types(xsdcompiler_t *compiler)
{
/*
 * this file is automatically generated, but shall not be tested
 * when we build the dependency tree.
 */
#if !defined(MAKE_DEPENDS)
#include "roxsd-compiler-schema-gen.inc"
#endif

	return 0;
}

/*
 * Non static entry point
 */
int roxsdi_compiler_register_schema_grammar(xsdenv_t *xsdenv)
{
	xsdcompiler_t *compiler;

	compiler = roxsdi_compiler_new();
	if (!compiler)
		return -1;

	if (roxsdi_compiler_register_schema_types(compiler) < 0) {
		roxsdi_compiler_free(compiler);
		return -1;
	}

	if (roxsdi_compiler_register_root(compiler, "schema", "t_schema") < 0) {
		roxsdi_compiler_free(compiler);
		return -1;
	}

#if !defined(NDEBUG)
	/* check wether the compiler is correctly defined */
	roxsdi_compiler_check(compiler);
#endif

	xsdenv->xsdcompiler = list_pushfront(xsdenv->xsdcompiler, compiler);

	return 0;
}
